W=diag([0.5,1,1,1,0.5])
A=[1 -2; 1 -1; 1 0; 1 1; 1 2];
y=[0 0 2 4 4]';
WA=W*A;
wy=W*y;
beta=WA\wy

x=A(:,2);
xp=[-3 3];
plot(x,y,'o',xp,beta(1)+beta(2)*xp)
xlabel('x')
ylabel('y')
axis([-3 3 -3 6])